/*
 * Copyright (c) 2015, the Dart project authors.
 *
 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package vm.element

// This file is generated by the script: pkg/vm_service/tool/generate.dart in dart-lang/sdk.

import com.google.gson.JsonObject

/**
 * {@link MemoryUsage} 对象提供特定 isolate 在给定点的堆使用信息。
 */
class MemoryUsage(json: JsonObject) : Response(json) {

    /**
     * 由 Dart 对象保留的非 Dart 内存数量。例如，通过 Dart_NewFinalizableHandle、Dart_NewWeakPersistentHandle
     * 和 Dart_NewExternalTypedData 等 API 与 Dart 对象关联的内存。此使用量的准确性仅与 VM 嵌入器提供给这些
     * API 的值一样准确。此外部内存会施加 GC 压力，但与 heapUsage 和 heapCapacity 分开。
     */
    fun getExternalUsage(): Int {
        return getAsInt("externalUsage")
    }

    /**
     * 堆的总容量（以字节为单位）。这是从操作系统角度来看 Dart 堆使用的内存量。
     */
    fun getHeapCapacity(): Int {
        return getAsInt("heapCapacity")
    }

    /**
     * 当前堆内存使用量（以字节为单位）。堆使用量始终小于或等于堆容量。
     */
    fun getHeapUsage(): Int {
        return getAsInt("heapUsage")
    }
}
